;(function () {
  new Vue({
    el:'.flow-list',
    data:{
      flowList:[],
      flowNode:[],
      pages: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],
      lcName: [{name: '全部', code: '#'},{name: '合同流程', code: 'CT'},{name: '退租流程', code: 'WT'}],
      lcqjName: [{name: '全部', code: '#'},{name: '启用', code: 'Y'},{name: '停用', code: 'N'}],
      isShowImage:false,
      configFlag:false,
      params: {name:[],no:null,memo:null,state:[],currentPage:1,limit:['10'],totalPage:0,totalCount:0}
    },
    filters:{
      formatDate:function (item) {
        return hlDateUtil.formatUTCDate(item)
      },
      formatUndefined:function (item) {
        if(item == undefined)return '--'
        return item
      }
    },
    methods:{
			selectedCC (arr) {
				this.params.name = [arr[0].code]
			},
			selectedTypeCode (arr) {
				this.params.state = [arr[0].code]
			},
      //跳转页面
      goPage: function () {
        hlUrlUtil.goTo('assigneesCreate', {ddtab:true})
      },
      //重置
      resetFlow: function () {
        this.params={name:[],no:null,memo:null,state:[],currentPage:1,limit:['10'],totalCount:0,totalPage:0};
        this.getFlowListData()
      },
      // 搜索
      searchFlow: function () {
        this.params.currentPage = 1;
        this.getFlowListData()
      },
      // 获取流程列表数据
      getFlowListData:function() {
        var self = this;

        hlhttp.get({
          url:'bpm/bpdefs',
          data: {
            key_word: self.params.memo || '#',
            bpm_key: self.params.name.length ? self.params.name[0] : '#',
            valid: self.params.state.length ? self.params.state[0] : '#',
            version: self.params.no || '#',
            is_default: '#',
            page: self.params.currentPage,
            limit: self.params.limit[0]
          },
          success:function(data){
            self.flowList = data
            self.params.totalCount = data.totalCount
            self.params.totalPage = data.totalPage

          }
        })
      },
      //设置每页数据
      setGetFlowList: function (arr) {
        this.params.limit = [arr[0].code]
        this.params.currentPage = 1
        this.getFlowListData()
      },
      //启用停用
      setValid: function (v,id,k) {
        var self = this;
        var type = v == 'N' ? 'Y' : 'N';
        hlhttp.put({
          url: 'bpm/check_bpdef',
          data: {bpdef_id:id,bpm_key:k},
          success: function (res) {
            if (res.exist == 'Y') {
              hl.toast('当前流程正在被使用')
              return
            }
            hlhttp.put({
              url: 'bpm/valid',
              data: {opt:type,bpdef_id:id},
              success: function () {
                hl.toast('设置成功')
                self.getFlowListData()
              }
            })
          }
        })

      },
      //编辑
      goEdit: function (k,id) {
        hlUrlUtil.goTo('assigneesCreate',{bpmKey:k, id: id, ddtab:true})
      },
      // 获取流程节点数据
      getFlowNodeData:function (id) {
        var self = this;
        hlhttp.get({
          url:'bpdef_phases',
          data:{'bpdef_id':id},
          success:function(data){
            self.flowNode = data
            // 如果节点超过两个时将流程图高度定死为492px
            if(data.length > 1)$('.flowlist-image').css('height','492px');
          }
        })
      },
      showFlowImage:function (id) {
        this.isShowImage = true;
        this.getFlowNodeData(id)
      },
      closeFlowImage:function () {
        this.isShowImage = false;
      },
      // 前往流程配置
      config:function (id,type,bpmKey) {
        hlUrlUtil.goTo('assigneesConfig',{id:id,bpmKey:bpmKey, ddtab:true},true)
      },
      permissions:function(){
        var permissions = JSON.parse(window.localStorage.getItem('permissions'));
        if(permissions.indexOf('c81') > 0){ this.configFlag = true; }
      },
			////获取流程列表
			getFlowList () {
				hlhttp.get({
					url: 'configure/dict',
					data: {module_code: 'BPM', config_name: 'BPM_CONFIG_TYPE'},
					success: (data => {
						let newData = []
						let userinfo = JSON.parse(localStorage.getItem('userMes'))
						newData = hlArrayUtil.replaceData(data, [{key: 'dictDisplayName', rKey: 'name'}, {key: 'dictValue', rKey: 'code'}])
            newData.unshift({'code':'#','name':'全部'})
						if (userinfo.preSysCode.indexOf('SINOOCEAN') == -1) {
							newData.map((item, index) => {
								if (item.dictValue == 'RRAT') {
									newData.splice(index, 1)
								}
							})
						}
						this.params.name = [newData[0].code]
						this.lcName = newData
					})
				})
			}
    },
    mounted:function () {
			this.getFlowList()
      this.permissions()
      this.getFlowListData()
      hlSelectUi(false,false)
    }
  })
}())
